<template>
  <div class="profile-page">
    <!-- 顶部导航栏 -->
    <el-header class="page-header">
      <div class="back-btn" @click="$router.back()">
        <el-icon>
          <ArrowLeft/>
        </el-icon>
      </div>
      <h2 class="page-title">基本信息</h2>
      <div class="empty-btn"></div>
    </el-header>

    <!-- 主体内容区 -->
    <div class="profile-content">
      <el-card class="form-card">
        <el-form
            :model="profileForm"
            label-width="80px"
            class="profile-form"
            ref="profileFormRef"
        >
          <!-- 用户名 -->
          <el-form-item label="用户名">
            <el-input
                v-model="profileForm.nickname"
                placeholder="请输入昵称"
                maxlength="12"
                show-word-limit
            />
          </el-form-item>

          <!-- 性别 -->
          <el-form-item label="性别">
            <el-select
                v-model="profileForm.gender"
                placeholder="请选择性别"
                style="width: 100%"
            >
              <el-option label="男" value="男"/>
              <el-option label="女" value="女"/>
            </el-select>
          </el-form-item>

          <!-- 联系地址 -->
          <el-form-item label="地址">
            <el-input
                v-model="profileForm.address"
                placeholder="请输入地址"
                maxlength="50"
                show-word-limit
            />
          </el-form-item>

          <!-- 个人简介 -->
          <el-form-item label="个人简介">
            <el-input
                v-model="profileForm.intro"
                placeholder="请输入个人简介"
                type="textarea"
                :rows="3"
                maxlength="100"
                show-word-limit
            />
          </el-form-item>

          <el-form-item class="submit-btn-item">
            <el-button type="primary" class="submit-btn" @click="setUser">保存修改</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script>
import {ArrowLeft} from '@element-plus/icons-vue'
import {ElHeader, ElCard, ElForm, ElFormItem, ElInput, ElSelect, ElOption, ElButton, ElIcon, ElMessage} from 'element-plus'
import {getUser, setUser} from "../api/user.js";

export default {
  name: "Profile",
  components: {
    ArrowLeft, ElHeader, ElCard, ElForm, ElFormItem, ElInput, ElSelect, ElOption, ElButton, ElIcon
  },
  data() {
    return {
      profileForm: {
        nickname: '',
        gender: '',
        address: '',
        intro: '',
      }
    }
  }
  , methods: {
    async loadData() {
      let {data: data} = await getUser()
      console.log(data)
      this.profileForm = data.data
      console.log(this.profileForm)
    }
    ,async setUser(){
      let {data:data}=await setUser(this.profileForm)
      console.log(data)
      if (data.code===200){
        ElMessage.success(data.msg)
      }else {
        ElMessage.error(data.msg)
      }
    }
  }
  , mounted() {
    this.loadData()
  }
}
</script>

<style scoped>
.profile-page {
  width: 100vw;
  min-height: 100vh;
  background-color: #f5f7fa;
  font-size: 14px;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background-color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.back-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  cursor: pointer;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.empty-btn {
  width: 32px;
  height: 32px;
}

.profile-content {
  padding: 16px;
}

.form-card {
  border-radius: 8px;
  background-color: #fff;
  overflow: hidden;
}

.profile-form {
  padding: 16px;
}

.profile-form .el-form-item {
  margin-bottom: 16px;
}

.profile-form .el-input__inner,
.profile-form .el-select__wrapper {
  height: 44px;
  line-height: 44px;
}

.profile-form .el-textarea__inner {
  min-height: 100px;
}

.submit-btn-item {
  margin-bottom: 0;
  margin-top: 8px;
}

.submit-btn {
  width: 100%;
  height: 44px;
  font-size: 16px;
}
</style>